########################################################################################
# TARGET = target_lib_name
# INCDIR = include_dir1 include_dir2
# LIBDIR = lib_dir1 lib_dir2
# SRCDIR = dir1 dir2
#	      
# CCOPTIONS = -march=pentium4 -pipe -fomit-frame-pointer -O3 -Wall 
# LDOPTIONS = 
#
# [or example]
# debug: CCOPTIONS = -D_DEBUG
# debug : rebuild
#
# release:CCOPTIONS = -D_RELEASE
# release :rebuild
#
# INSTALL_LIB_DIR = /usr/local/include
# INSTALL_BIN_DIR = /usr/local/bin
#
# STRIP = strip -s
#
# include liba.mk
#
# # clean:
# # distclean:
# # rebuild:
########################################################################################
# default options
CC_DEFAULT_OPTIONS =
########################################################################################
# tools setting
CC	= cc
CPP	= cc -E
CXX	= g++
LD	= gcc
AR	= ar -ruv
RANLIB	= ranlib
MKDIR	= mkdir -p
COPY	= cp -f
REMOVE	= rm -f
SLEEP	= sleep 1
ifeq ("", "$(STRIP)")
STRIP	= @ls -l
endif
########################################################################################
# object sets setting
SDIR    = . $(SRCDIR)
SRCS    = $(wildcard $(addsuffix /*.c,$(SDIR))) $(wildcard $(addsuffix /*.cc,$(SDIR))) $(wildcard $(addsuffix /*.cpp,$(SDIR)))
INCS    = $(wildcard *.h) $(wildcard *.hpp) $(wildcard *.hxx) $(wildcard *.inl)
OBJS    = $(patsubst %.c,%.o,$(patsubst %.cc,%.o,$(patsubst %.cpp,%.o,$(SRCS))))
DEPS    = $(patsubst %.o,%.d,$(OBJS))
########################################################################################
# variables
# variables
CC_INC_DIR = -I. $(addprefix -I,$(INCDIR))

CCFLAGS  = $(CC_INC_DIR) $(CC_DEFAULT_OPTIONS) $(CCOPTIONS) 
########################################################################################
# rules
.PHONY : all clean distclean rebuild

all: $(TARGET)

$(TARGET):$(OBJS)
	@$(MKDIR) `dirname $(TARGET)`
	$(AR) $@ $(OBJS)
	$(RANLIB) $@
	$(STRIP) $@
	@$(SLEEP)

.cpp.o:
	$(CXX) -c $< -o $@ $(CCFLAGS) -MMD
.cc.o:
	$(CXX) -c $< -o $@ $(CCFLAGS) -MMD
.c.o:
	$(CC) -c $< -o $@ $(CCFLAGS) -MMD


-include $(DEPS)

########################################################################################
# other tools
clean:
	$(REMOVE) $(OBJS)
	$(REMOVE) $(DEPS)

distclean: clean
	$(REMOVE) $(TARGET)

rebuild: clean all
